package com.twu.biblioteca.command;

import com.twu.biblioteca.domain.Library;
import com.twu.biblioteca.domain.LibraryService;

import java.util.HashMap;
import java.util.Map;

public class CommandFactory {
    private static String HELP_COMMAND = "help";
    private static String LIST_BOOKS_COMMAND = "List Books";
    private static String LIST_MOVIES_COMMAND = "List Movies";
    private static String MY_INFORM_COMMAND = "User Account";
    private static String CHECK_OUT_BOOK = "Checkout Book";
    private static String CHECK_OUT_Movie = "Checkout Movie";
    private static String RETURN_BOOK = "Return Book";
    private static String RETURN_Movie = "Return Movie";

    private Map<String, Command> commands = new HashMap<String, Command>();
    private LibraryService libraryService;

    public CommandFactory(Library library) {
        libraryService = new LibraryService(library);
        initCommands(library);
    }

    private void initCommands(Library library) {
        commands.put(LIST_BOOKS_COMMAND, new ListBooksCommand(library));
        commands.put(LIST_MOVIES_COMMAND, new ListMoviesCommand(library));
        commands.put(HELP_COMMAND, new HelpCommand());
        commands.put(CHECK_OUT_BOOK, new CheckoutBookCommand(libraryService));
        commands.put(CHECK_OUT_Movie, new CheckoutMovieCommand(libraryService));
        commands.put(RETURN_BOOK, new ReturnBookCommand(libraryService));
        commands.put(RETURN_Movie, new ReturnMovieCommand(libraryService));
        commands.put(MY_INFORM_COMMAND, new ShowCustomerMsgCommand(library));

    }

    public Command getCommand(String command) {
        Command cmd = commands.get(command);
        return cmd == null ? new InvalidCommand() : cmd;
    }
}
